package personnal.blogprinter.data;

public class PostError {
	
	private Integer postId;

	private Throwable cause;

	public PostError(Integer id, Exception exception) {
		super();
		this.postId = id;
		if (exception != null) {
			Throwable nestedCause = exception;
			while (nestedCause.getCause() != null) {
				nestedCause = nestedCause.getCause();
			}
			this.cause = nestedCause;
		}
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append(postId).append(';');
		if (cause != null) {
			builder.append(cause.getClass()).append(';');
			builder.append(cause.toString()).append(';');
		} else {
			builder.append("No exception type;");
			builder.append("No exception message;");
		}
		return builder.toString();

	}
}
